package com.apesource.mallproject.dao;

import com.apesource.mallproject.pojo.Seller;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ISellerDao {
    //查询所有商家信息
    @Select("select * from seller")
    public List<Seller> findAll();

    //查询待审核的商家信息
    @Select("select * from seller where `status` = 0")
    public List<Seller> findStatus();

    //修改商家状态为已审核
    @Update("UPDATE seller SET `status`= 1 WHERE seller_id = #{sellerId}")
    public void updateStatus(@Param("sellerId") Integer sellerId);

    //修改商家的状态为审核未通过
    @Update("UPDATE seller SET `status`= 2 WHERE seller_id = #{sellerId}")
    public void updateNoStatus(@Param("sellerId") Integer sellerId);

    //删除已经关闭的商家
    @Delete("delete from seller where seller_id = #{sellerId}")
    public void delSeller(@Param("sellerId") Integer sellerId);

    //关闭商家
    @Update("UPDATE seller SET `status`= 3 WHERE seller_id = #{sellerId}")
    public void updateCloseStatus(@Param("sellerId") Integer sellerId);


    //模糊动态查找
    @SelectProvider(type = SellerProvider.class, method = "getSeller")
    public List<Seller> showLike(String name, String nickName, Integer status);

    class SellerProvider {
        public String getSeller(String name, String nickName, Integer status) {

            String sql = "SELECT * FROM seller where 1=1";
            if (name != null && !name.equals("")) {
                String sname = "'%" + name + "%'";
                sql += " and name like " + sname;
            }
            if (nickName != null && !nickName.equals("")) {

                String snickName = "'%" + nickName + "%'";
                sql += " and nick_name like " + snickName;
            }
            if (status != null && !status.equals("") && status != 5) {
                Integer istatus = status;
                sql += " and status" + "=" + istatus;
            }
            return sql;

        }
    }
}
